package com.jn.exam.easypoi.service.impl;

import com.jn.exam.easypoi.entity.Question;
import com.jn.exam.easypoi.mapper.QuestionMapper;
import com.jn.exam.easypoi.service.OssFeignService;
import com.jn.exam.easypoi.service.QuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.FutureResult;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.File;
import java.util.concurrent.Future;

/**
 * <p>
 * 总题库 服务实现类
 * </p>
 *
 * @author 江南大学1033190417
 * @since 2022-01-22
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {

    @Autowired
    private OssFeignService ossFeignService;

    @Override
    @Async
    public Future<Boolean> test() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
        return new AsyncResult<>(true);
    }

    @Override
    @Async
    public Future<Boolean> saveQuestionFromExcel(Question question) throws Exception{
        int insert = baseMapper.insert(question);
        System.out.println(Thread.currentThread().getName());
        if (insert==1){
            return new AsyncResult<>(true);
        }
        return new AsyncResult<>(false);
    }
}
